<template>
  <NuxtLayout>
    <div class="page-container mx-auto mt-[78px] overflow-x-hidden text-white md:max-w-6xl">
      <el-breadcrumb separator="/">
        <el-breadcrumb-item :to="{ path: '/admin' }">首页</el-breadcrumb-item>
        <el-breadcrumb-item> 文章列表 </el-breadcrumb-item>
      </el-breadcrumb>

      <h1 class="pt-6 text-2xl">文章管理</h1>

      <div class="flex justify-end border-b border-white pb-4">
        <div class="cursor-pointer rounded-xl border px-4 py-2 text-sm" @click="toCreate">新增</div>
      </div>
      <client-only>
        <el-table :data="articleList" class="bg-transparent" :max-height="600">
          <!-- <el-table-column prop="id" label="文章id" width="100" align="center" /> -->
          <el-table-column prop="title" label="文章标题" />
          <el-table-column prop="secondTitle" label="副标题" />
          <el-table-column prop="createTime" label="创建时间" width="180" align="center" />
          <el-table-column prop="updateTime" label="更新时间" width="180" align="center" />
          <el-table-column label="操作" width="120" fixed="right" align="center">
            <template #default>
              <el-button class="cursor-pointer text-red-500">编辑</el-button>
            </template>
          </el-table-column>
        </el-table>
      </client-only>
    </div>
  </NuxtLayout>
</template>

<script setup lang="ts">
interface IArticle {
  id: number
  title: string
  secondTitle: string
  createTime: string
  updateTime: string
  status: number
}

// const articleList = ref<Array<IArticle>>([])

const router = useRouter()
const toCreate = () => {
  router.push('/admin/article/create')
}

let currentPage = ref(1)
let pageSize = ref(20)

let res = await useFetch('/api/articles', {
  method: 'get',
  params: {
    currentPage: currentPage.value,
    pageSize: pageSize.value,
    categoryId: 0
  }
})

let list = []
if (res && res.data.value) {
  list = res.data.value.data.list || []
}

let articleList = ref(list)
</script>

<style lang="scss" scoped></style>
